import org.yaml.snakeyaml.Yaml;

import java.io.*;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;

/**
 * 最严格的测试
 * */
public class test {
    @Retention(RetentionPolicy.RUNTIME)
    public @interface O {}

    static class A{
        @O public boolean aBoolean = true;
        @O public byte aByte = 10;
        @O public double aDouble = 120.2;
        @O public float aFloat = 12.8F;
        @O public int anInt = 5192;
        @O public long aLong = 456;
        @O public short aShort = 4;
        @O public char aChar = 'w';
        @O public String aString = "啊啊啊";
        @O public List<List<List<String>>> lllllist = Arrays.asList(
                Arrays.asList(
                        Arrays.asList("aaaa","ddddd","asdsadas"),
                        Arrays.asList("aaaa","asdasd","asdsadas","asdasdas")
                ),
                Arrays.asList(
                        Arrays.asList("123123")
                )
        );

        @Override
        public String toString() {
            return "A{" +
                    "aBoolean=" + aBoolean +
                    ", aByte=" + aByte +
                    ", aDouble=" + aDouble +
                    ", aFloat=" + aFloat +
                    ", anInt=" + anInt +
                    ", aLong=" + aLong +
                    ", aShort=" + aShort +
                    ", aChar=" + aChar +
                    ", aString='" + aString + '\'' +
                    ", lllllist=" + lllllist +
                    '}';
        }
//        public static void printf() {
//            String a = "A{" +
//                    "aBoolean=" + aBoolean +
//                    ", aByte=" + aByte +
//                    ", aDouble=" + aDouble +
//                    ", aFloat=" + aFloat +
//                    ", anInt=" + anInt +
//                    ", aLong=" + aLong +
//                    ", aShort=" + aShort +
//                    ", aChar=" + aChar +
//                    ", aString='" + aString + '\'' +
//                    '}';
//            System.out.println(a);
//            System.out.println(lllllist);
//        }
    }

    public static void main(String[] args) throws IOException {
        Yaml yaml = new Yaml();

        A a = null;
        try {
            a = yaml.loadAs(new InputStreamReader(Files.newInputStream(Paths.get("严格测试.yml")), StandardCharsets.UTF_8),A.class);

        }catch (Throwable throwable){
            throwable.printStackTrace();
        }

        yaml.dump(a==null?new A():a,new OutputStreamWriter(Files.newOutputStream(Paths.get("严格测试.yml"))));

        System.out.println(a);


//
//        new YamlConfigFieldTool().load(new File("严格测试.yml")).setAnnotationClass(O.class)
//                .as(A.class)
//                .run((tool)->A.printf())
//                .setPrefix("my.ok.go.").as(A.class)
//                .run(configFieldTool -> A.printf())
//                .save(new File("严格测试.yml"));


    }
}
